# -*- coding: utf-8 -*-
'''
Created on 2013-6-1
人物、物品通用
@author: 不懂d叛逆
'''
import ccjhObj

class ccjhMan(ccjhObj.ccjhObj):

	def __init__(self, data = None):
		self.data = {}
		self.data["N"] = "某人"
		self.wieldPos = 0
		self.LongID = 0
		self.team = -1
		if data:
			self.setTo(data)
		return

	def setTo(self, obj):
		super(ccjhMan, self).setTo(obj)
		try:
			self.LongID = int(self.get("O"))
		except:
			self.LongID = int(self.get("T"))
		Type = obj.getType()
		if Type == 23:
			tstr = self.get("tea")
			if len(tstr) > 0:
				self.team = int(tstr)
			tstr = self.get("ap")
			if len(tstr) > 0:
				if self.team == -1:
					self.team = 0
		return

	def ToString(self, bID = True):
		amount = self.get("a")
		try:
			amount = int(amount)
		except:
			amount = 0
		result = ""
		if bID:
			title = self.get("t")
			Name = self.get("N")
			ID = self.get("I")
			if len(title) > 0:
				result = "%s %s(%s)" % (title, Name, ID)
			else:
				if amount > 1:
					result = "数量%d的%s(%s)" % (amount, Name, ID)
				elif len(ID) > 0:
					result = "%s(%s)" % (Name, ID)
				else:
					result = Name
			dis = self.get("dis")
			if len(dis) > 0:
				result += "<%s>" % (dis,)
			elif self.get("exe") == "1":
				result += "<打坐中>"
			elif self.get("net") == "1":
				result += "<断线中>"
			elif self.get("poi") == "1":
				result += "<毒发中>"
			elif self.get("net") == "1":
				result += "<发呆中>"
		else:
			if amount > 1:
				result = "数量%d的%s" % (amount, self.get("N"))
			else:
				result = self.get("N")
			wieldPosString = {1:"(头盔)",
					2:"(左耳)",
					3:"(右耳)",
					4:"(耳环)",
					5:"(颈)",
					6:"(左手)",
					7:"(右手)",
					8:"(手)",
					9:"(左腕)",
					10:"(右腕)",
					11:"(手腕)",
					12:"(铠甲)",
					13:"(腰带)",
					14:"(靴子)",
					15:"(斗篷)",
					16:"(手套)",
					17:"(双手)",
					18:"(指环)",
					19:"(衣服)"}
			if self.wieldPos in wieldPosString:
				result = result + wieldPosString[self.wieldPos]
		return result

	def CombatString(self):
		name = self.get("N")
		if self.team != -1:
			dis = self.get("dis")
			if len(dis) > 0:
				name += "<%s>" % (dis,)
			elif self.get("exe") == "1":
				name += "<打坐中>"
			elif self.get("net") == "1":
				name += "<断线中>"
			elif self.get("poi") == "1":
				name += "<毒发中>"
			return "%-14s%-7s%-5s未知" % (name, self.get("sta"), self.get("ap"))
		else:
			return name
